// 题意：dna序列只由 {'A', 'G', 'T', 'C'} 组成，给定n个疾病片段，
//       给定一个dna片段，问最少修改几个位置使得dna片段不包含任何疾病片段。
//
// 题解：用ac自动机做。先建立ac自动机的状态机。然后在上面做dp。
//       用dp[i][j]表示匹配了前缀长度为i的串，最后匹配状态为trie上的j，
//       最少需要修改几次。然后不断向后转移就行。
//
// run: time $exec < input
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>

std::map<char, int> dna_index;
std::map<int, char> dna;

namespace tue
{
	int const alphabet_size = 4;
	int const max_size = 100000;
	int const dq_size = 100000;

	int next[max_size][alphabet_size];
	int fail[max_size];
	int word_tail_count[max_size];

	int dq[dq_size];
	int head, tail;

	int dq_next(int x) { return (x + 1) % dq_size; }
	int dq_prev(int x) { return (x + dq_size - 1) % dq_size; }
	void clear() { head = tail = 0; }
	bool empty() { return head == tail; }
	int front() { return dq[head]; }
	void push_back(int x) { dq[tail] = x; tail = dq_next(tail); }
	void push_front(int x) { dq[head = dq_prev(head)] = x; }
	void pop_front() { head = dq_next(head); }

	struct trie
	{
		trie() { reset(); }

		void reset() { current_free = 0; root = allocate(); }
		int get_root() { return root; }
		int get_trie_size() { return current_free; }

		void insert(std::string const & s)
		{
			int now = root;
			int len = s.size();
			for (int i = 0; i < len; now = next[now][dna_index[s[i++]]])
				if (next[now][dna_index[s[i]]] == -1)
					next[now][dna_index[s[i]]] = allocate();
			word_tail_count[now]++;
		}

		void make_ac_automaton()
		{
			clear();
			fail[root] = root;
			for (int ch = 0; ch < alphabet_size; ch++)
				if (next[root][ch] == -1)
					next[root][ch] = root;
				else {
					fail[next[root][ch]] = root;
					push_back(next[root][ch]);
				}

			while (!empty()) {
				int now = front(); pop_front();
				for (int ch = 0; ch < alphabet_size; ch++)
					if (next[now][ch] == -1)
						next[now][ch] = next[fail[now]][ch];
					else {
						fail[next[now][ch]] = next[fail[now]][ch];
						push_back(next[now][ch]);
					}
			}
		}

	private:

		int allocate()
		{
			for (int i = 0; i < alphabet_size; i++)
				next[current_free][i] = -1;
			word_tail_count[current_free] = 0;
			return current_free++;
		}

		int current_free;
		int root;
	};
}

int const inf = 1 << 28;
int const maxn = 1007;
int dp[maxn][maxn];
int n, m, root;
std::string s;

int main()
{
	std::ios::sync_with_stdio(false);

	dna_index['A'] = 0; dna_index['G'] = 1; dna_index['C'] = 2; dna_index['T'] = 3;
	dna[0] = 'A'; dna[1] = 'G'; dna[2] = 'C'; dna[3] = 'T';

	tue::trie aca;
	for (int ti = 1; std::cin >> n && n; ti++) {
		std::cout << "Case " << ti << ": ";
		aca.reset();
		for (int i = 0; i < n; i++) {
			std::cin >> s;
			aca.insert(s);
		}
		aca.make_ac_automaton();
		std::cin >> s;

		n = s.size();
		m = aca.get_trie_size();
		root = aca.get_root();

		for (int i = 0; i <= n; i++)
			for (int j = 0; j < m; j++) dp[i][j] = inf;

		dp[0][root] = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				if (dp[i][j] >= inf) continue;
				for (int k = 0; k < 4; k++) {
					bool disease = false;
					int nj = tue::next[j][k];
					for (int tmp = nj; tmp != root; tmp = tue::fail[tmp]) {
						if (tue::word_tail_count[tmp]) {
							disease = true;
							break;
						}
					}
					if (!disease)
						dp[i + 1][nj] = std::min(dp[i + 1][nj],
								dp[i][j] + int(dna[k] != s[i]));
				}
			}
		}

		int ans = inf;
		for (int i = 0; i < m; i++) ans = std::min(ans, dp[n][i]);
		if (ans >= inf) ans = -1;
		std::cout << ans << '\n';
	}
}

